package com.zznj.xzjc.activity.index.push;

import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.vondear.rxtool.RxActivityTool;
import com.zznj.xzjc.R;
import com.zznj.xzjc.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by JY on 2017/11/15.
 */

public class IndexPushActivity extends BaseActivity {

    @BindView(R.id.searchEdit)
    EditText searchEdit;
    @BindView(R.id.searchBtn)
    View searchBtn;

    @BindView(R.id.btn_zdgl)
    View btn_zdgl;
    @BindView(R.id.btn_zcfb)
    View btn_zcfb;
    @BindView(R.id.btn_dxal)
    View btn_dxal;
    @BindView(R.id.btn_tzgg)
    View btn_tzgg;



    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_index_push_layout;
    }

    @Override
    public void initView() {
        setTitle("消息推送");
        btnRight.setVisibility(View.GONE);

        /***
         * 监听输入框是否点击了搜索
         */
        searchEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_SEARCH) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//关闭软键盘
                    Bundle bundle = new Bundle();
                    bundle.putString("key", searchEdit.getText().toString());
                    bundle.putInt("index", 0);
                    RxActivityTool.skipActivity(activity, ActivityPushMain.class, bundle);
                    return true;
                }
                return false;
            }
        });
    }

    @Override
    public void initData() {

    }


    private int index = 0;
    @OnClick({R.id.searchBtn,R.id.btn_zdgl,R.id.btn_zcfb,R.id.btn_dxal,R.id.btn_tzgg})
    public void onClick(View v) {
        if (R.id.searchBtn == v.getId()) {
            Bundle bundle = new Bundle();
            bundle.putString("key", searchEdit.getText().toString());
            bundle.putInt("index", 0);
            RxActivityTool.skipActivity(activity, ActivityPushMain.class, bundle);
        } else {
            if (R.id.btn_zdgl == v.getId()) {
                index = 1;
            } else if (R.id.btn_zcfb == v.getId()) {
                index = 2;
            } else if (R.id.btn_dxal == v.getId()) {
                index = 3;
            } else if(R.id.btn_tzgg == v.getId()){
                index = 4;
            }
            Bundle bundle = new Bundle();
            bundle.putInt("index", index);
            RxActivityTool.skipActivity(activity, ActivityPushMain.class, bundle);
        }

    }
}
